package com.sg.service.biz.component.nb;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.biz.component.common.MultitermOptionCodeTransitionMultirowResultDto;
import com.sg.dto.biz.component.req.ImplementMultitermOptionCodeTransitionMultirowResultReqDto;
import com.sg.dto.biz.component.req.ImplementPhpFileUploadReqDto;
import com.sg.dto.biz.component.req.ImplementUploadFileNameToFieldReqDto;
import com.sg.dto.biz.component.res.ImplementMultitermOptionCodeTransitionMultirowResultRespDto;
import com.sg.dto.biz.component.res.ImplementPhpFileUploadRespDto;
import com.sg.dto.biz.component.res.ImplementUploadFileNameToFieldRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
public class NbNetDisk {
    /**
     * code:multiColumnToMultiRow
     * name:M2-转本地存储上传配置信息
     * desc:undefined
     * gen by moon at 12/4/2024, 7:23:48 AM
     **/
    @Trace(operationName = "M2-转本地存储上传配置信息")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementMultitermOptionCodeTransitionMultirowResultRespDto implementMultitermOptionCodeTransitionMultirowResult(ImplementMultitermOptionCodeTransitionMultirowResultReqDto reqDto) {
        ImplementMultitermOptionCodeTransitionMultirowResultRespDto retData = new ImplementMultitermOptionCodeTransitionMultirowResultRespDto();
        Field[] declaredFields = ImplementMultitermOptionCodeTransitionMultirowResultRespDto.class.getDeclaredFields();
        Map<String, Field> tarGetValueIndex = new HashMap<>();
        for (Field field : declaredFields) {
            tarGetValueIndex.put(field.getName(), field);
        }
        for (MultitermOptionCodeTransitionMultirowResultDto oneOption : reqDto.getMultitermOptionCodeTransitionMultirowResultList()) {
            Field tarGetField = tarGetValueIndex.get(CommonFunctionHelper.underlineToHump(oneOption.getConfOptionCode()));
            if (tarGetField != null) {
                try {
                    tarGetField.setAccessible(true);
                    if (tarGetField.getType().equals(Long.class)) {
                        tarGetField.set(retData, Long.valueOf(oneOption.getEndValue()));
                    } else if (tarGetField.getType().equals(Long.class)) {
                        tarGetField.set(retData, Long.valueOf(oneOption.getEndValue()));
                    } else {
                        tarGetField.set(retData, oneOption.getEndValue());
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }

        }
        return retData;
    }

    /**
     * code:uploadFileNameToSingleField
     * name:M2执行上传文件名称转单字段（特殊方法）
     * desc:undefined
     * gen by moon at 12/6/2024, 10:02:37 PM
     **/
    @Trace(operationName = "M2执行上传文件名称转单字段（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementUploadFileNameToFieldRespDto implementUploadFileNameToField(ImplementUploadFileNameToFieldReqDto reqDto) {
        ImplementUploadFileNameToFieldRespDto retData = new ImplementUploadFileNameToFieldRespDto();
        if (reqDto.getResourceFileName() != null) {
            String[] splitor = reqDto.getResourceFileName().split("\\.");
            if (splitor != null && splitor.length > 0) {
                retData.setResourceFileName(splitor[0]);
                retData.setResourceFileExtension(splitor[1]);
                retData.setPhyFileUuid(CommonFunctionHelper.getUid());
            }
        }
        return retData;
    }

    /**
     * code:phpFileUpload
     * name:M2执行物理文件上传（特殊方法）
     * desc:undefined
     * gen by moon at 12/6/2024, 10:02:54 PM
     **/
    @Trace(operationName = "M2执行物理文件上传（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementPhpFileUploadRespDto implementPhpFileUpload(ImplementPhpFileUploadReqDto reqDto) {
        // TODO ruizhe skai dong ; 12/6/2024, 10:02:54 PM
        return new ImplementPhpFileUploadRespDto();
    }
    //手工接入方法
}
